﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartSpace.Web;

namespace SmartSpace.News.UI.Pages
{
    public partial class EditAssetCategory : System.Web.UI.Page
    {
        private Guid _categoryId { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            _categoryId = Guid.Parse(Request.QueryString["news_category_id"]);

            if (!IsPostBack)
            {
                SetValueForUI();
            }
        }

        private void SetValueForUI()
        {
            AssetService service = new AssetService();
            AssetCategory category = service.GetCategory(_categoryId).Data;
            if (category != null)
            {
                _ctlCode.Text = category.Code;
                _ctlName.Text = category.Name;
                _ctrlDesc.Text = category.Description;
            }
        }

        protected void _ctlBtnSave_Click(object sender, EventArgs e)
        {
            AssetService service = new AssetService();
            AssetCategory category = service.GetCategory(_categoryId).Data;
            if (category != null)
            {
                category.Name = _ctlName.Text;
                category.Description = _ctrlDesc.Text;
                service.SaveCategory(category);
            }

            SsPage.Return(this, new { id = category.Id });
        }
    }
}